BEGIN;

DROP TABLE room_place;
CREATE TABLE room_place (
  id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  object_state VARCHAR(30) NOT NULL,
  sid VARCHAR(32) NOT NULL,
  room_id INT(11) NOT NULL,
  row_number INT(11) NOT NULL,
  column_number INT(11) NOT NULL,
  label VARCHAR(12),
  type VARCHAR(30) NOT NULL,
  FOREIGN KEY (room_id) REFERENCES room(id) ON DELETE CASCADE,
  UNIQUE (sid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


ALTER TABLE room_place ADD INDEX room_place_sid_idx (sid);
ALTER TABLE room_place ADD INDEX room_place_object_state_idx (object_state);
ALTER TABLE room_place ADD INDEX room_place_room_id_idx (room_id);

CREATE TABLE row_header (
  id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  object_state VARCHAR(30) NOT NULL,
  sid VARCHAR(32) NOT NULL,
  room_id INT(11) NOT NULL,
  row_number INT(11) NOT NULL,
  label VARCHAR(12),
  FOREIGN KEY (room_id) REFERENCES room(id) ON DELETE CASCADE,
  UNIQUE (sid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE row_header ADD INDEX row_header_sid_idx (sid);
ALTER TABLE row_header ADD INDEX row_header_object_state_idx (object_state);
ALTER TABLE row_header ADD INDEX row_header_room_id_idx (room_id);

COMMIT;